package databasetools;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import Main.MovieDay;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class xmlToARFF
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{

		try
		{
			FileWriter outFile = new FileWriter("moveis.arff");
			PrintWriter out = new PrintWriter(outFile);

			out.println("@RELATION movies");
			out.println("@ATTRIBUTE date  DATE \"yyyy-MM-dd\"");
			out.println("@ATTRIBUTE city   STRING");
			out.println("@ATTRIBUTE cinema  STRING");
			out.println("@ATTRIBUTE seats NUMERIC");
			out.println("@ATTRIBUTE title   STRING");
			out.println("@DATA");

			// Directory path here
			String path = "C:/Users/fzuend/Desktop/kinofusun/data/";

			String fn;
			File folder = new File(path);
			File[] listOfFiles = folder.listFiles();

			for (int i = 0; i < listOfFiles.length; i++)
			{

				if (listOfFiles[i].isFile())
				{
					fn = listOfFiles[i].getName();
					if (fn.endsWith(".xml"))
					{
						XStream xstream = new XStream(new DomDriver("UTF-8"));
						MovieDay movieDay = (MovieDay) xstream.fromXML(new File(path + fn));

						out.print(movieDay.toARFFData());
						System.out.println(fn);
					}
				}
			}

			out.close();

		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
